home *** CD-ROM | disk | FTP | other *** search
/ Java Primer Plus / Java Primer Plus (Waite Group Proess)(1996).iso / java_Win / demo / ImageMap / HrefButtonArea.class (.txt) < prev    next >
Encoding:
Java Class File  |  1995-10-12  |  2.6 KB  |  65 lines

  1. import java.awt.Graphics;
  2. import java.awt.Image;
  3. import java.net.MalformedURLException;
  4. import java.net.URL;
  5.  
  6. class HrefButtonArea extends ImageMapArea {
  7.    URL anchor;
  8.    Image upImage;
  9.    Image downImage;
  10.    boolean pressed = false;
  11.    int border = 5;
  12.  
  13.    public void handleArg(String arg) {
  14.       try {
  15.          this.anchor = new URL(super.parent.getDocumentBase(), arg);
  16.       } catch (MalformedURLException var2) {
  17.          this.anchor = null;
  18.       }
  19.  
  20.       if (this.border * 2 > super.W || this.border * 2 > super.H) {
  21.          this.border = Math.min(super.W, super.H) / 2;
  22.       }
  23.  
  24.    }
  25.  
  26.    public void makeImages() {
  27.       this.upImage = super.parent.getHighlight(super.X, super.Y, super.W, super.H, new ButtonFilter(false, super.parent.hlpercent, this.border, super.W, super.H));
  28.       this.downImage = super.parent.getHighlight(super.X, super.Y, super.W, super.H, new ButtonFilter(true, super.parent.hlpercent, this.border, super.W, super.H));
  29.    }
  30.  
  31.    public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
  32.       if (img == (this.pressed ? this.downImage : this.upImage)) {
  33.          return super.parent.imageUpdate(img, infoflags, x + super.X, y + super.Y, width, height);
  34.       } else {
  35.          return img == this.downImage || img == this.upImage;
  36.       }
  37.    }
  38.  
  39.    public void highlight(Graphics g, boolean on) {
  40.       if (on) {
  41.          ((ImageMapArea)this).setHighlight(this.pressed ? this.downImage : this.upImage);
  42.       }
  43.  
  44.       super.highlight(g, on);
  45.       ((ImageMapArea)this).showStatus(on && this.anchor != null ? "Go To " + this.anchor.toExternalForm() : null);
  46.    }
  47.  
  48.    public void press() {
  49.       super.parent.repaint();
  50.       this.pressed = true;
  51.    }
  52.  
  53.    public void lift(int x, int y) {
  54.       this.pressed = false;
  55.       super.parent.repaint();
  56.       if (((ImageMapArea)this).inside(x, y) && this.anchor != null) {
  57.          ((ImageMapArea)this).showDocument(this.anchor);
  58.       }
  59.  
  60.    }
  61.  
  62.    public HrefButtonArea() {
  63.    }
  64. }
  65.